javascript change table row color based on value

142

javascript change table row color based on value -

var rows = document.getElementById("trans_separate").getElementsByTagName("tbody")
  [0].getElementsByTagName("tr");

    // loops through each row
    for (i = 0; i < rows.length; i++) {cells = rows[i].getElementsByTagName('td');

            if (cells[0].innerHTML == 'R')
                rows[i].className = "red";

            if (cells[0].innerHTML == 'Y')
                rows[i].className = "yellow";           
 }

Comments

Submit
0 Comments